const api = require('../../../utils/interface.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    type:''
  }, 

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.data.type = options.type
    this.getCardList()
  },
  onShow(){
  },
  go_memberCard(e) {
    let uuid = e.currentTarget.dataset.uuid
    let cardId = e.currentTarget.dataset.cardid
    wx.navigateTo({
      url: '/pages/memberCard/memberCard?uuid=' + uuid + '&type=1&cardId=' + cardId,
    })
  },
  getCardList() {
    wx.showLoading({
      title: '加载中...',
    })
    let user = wx.getStorageSync('userInfo')
    api.getMemberInfoCard({ memberId: user.id }).then(res => {
      wx.hideLoading()
      if (res.data.result && res.data.result.length) {
        this.data.list = []
        console.log(this.data.type)
        res.data.result.map(item => {
          if (this.data.type == 1 && item.parentId == 0){
            this.data.list.push(item)
          }
          if (this.data.type == 2 && item.parentId != 0) {
            this.data.list.push(item)
          }
          switch (item.productName) {
            case '汽油':
              item.color = "#4A8BFC"
              break;
            case '柴油':
              item.color = "#F56C6C"
              break;
            case 'LNG':
              item.color = "#02B663"
              break;
          }
        })
        console.log(this.data.list)
        this.setData({
          list: this.data.list
        })
      }

    })
  },
 
})